package com.example.kotlin

/**
 * @ClassName: Magic
 * @Description: java类作用描述
 * @Author: chenmengjia
 * @Date: 2022/2/3 15:34
 */
class Magic<T>(vararg item: T) {
    private var subject: Array<out T> = item
    var available = false
    fun openBox() {

    }

    fun fetch(index: Int): T? = subject[index].takeIf { available }
    fun <R>fetch(f: (T) -> R, index: Int):R?{
        return f(subject[index])
    }
}